package cn.lanqiao.system.service.impl;

import cn.lanqiao.common.entity.Film;
import cn.lanqiao.common.vo.FilmCheckVo;
import cn.lanqiao.common.vo.FilmVo;
import cn.lanqiao.system.mapper.FilmMapper;
import cn.lanqiao.system.service.FilmService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
@Repository
public class FilmServiceImpl implements FilmService {

    @Autowired
    private FilmMapper filmMapper;
    @Override
    public List<FilmVo> getAll() {
        return filmMapper.getAll();
    }
    @Override
    public int insert(Film film) {
        return filmMapper.insert(film);
    }
    @Override
    public int updateByPrimaryKey(Film film) {
        return filmMapper.updateByPrimaryKey(film);
    }

    @Override
    public List<FilmVo> findByName(String value) {
        return filmMapper.findByName(value);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return filmMapper.deleteByPrimaryKey(id);
    }

    @Override
    public FilmVo findById(Integer id) {

        return filmMapper.findById(id);
    }
    @Override
    public int save(Film film) {
        if (film.getId() != null) {
            return filmMapper.updateByPrimaryKeySelective(film);
        } else if (film.getId() == null) {
            return filmMapper.insertSelective(film);
        }
        return 0;
    }

    @Override
    public PageInfo<FilmVo> getPageFilm(int pageNo, int pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        List<FilmVo> list = filmMapper.getAll();
        PageInfo<FilmVo> page = new PageInfo<>(list);
        return page;
    }

    @Override
    public PageInfo<FilmCheckVo> getPageFilmInformation(int pageNo, int pageSize, String filmName, String info) {
        PageHelper.startPage(pageNo,pageSize);
        List<FilmCheckVo> FilmCheckVoList = filmMapper.getFilmInformation(filmName,info);
        PageInfo<FilmCheckVo> page = new PageInfo<>(FilmCheckVoList);
        return page;
    }

    @Override
    public int deleteByIds(Integer[] ids) {
        return filmMapper.deleteByIds(ids);
    }
}
